package com.shandao.shangxiu.util;

import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

public  class PatternCheck {

    /**
     * Email检查. 具体格式未知.
     */
    public static final String IS_EMAIL = "^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$";

    
    /**
     * 有效的手机号码
     */
    //public static final String IS_MOBILE ="^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";
    public static final String IS_MOBILE ="^(13|15|17|18)[0-9]{9}$";

    
    public static final String IS_ID = "^(\\d{15}$|^\\d{18}$|^\\d{17}(\\d|X|x))$";
    /**
     * 有效性检查.
     * 
     * @return ture or false
     * @param formValue
     *            字符串值
     * @param formatString
     *            字符串格式
     */
    public static boolean validateFormat(String formValue, String formatString) {
        boolean match = true;
        if (formatString == null || formatString.trim().length() == 0) {
            return match;
        }
        try {
            match = Pattern.matches(formatString, formValue);
        } catch (PatternSyntaxException e) {
        }
        if (!match) {
        }

        // add check character '
        if ((formValue.indexOf("'")) >= 0) {
            match = false;
        }
        return match;
    }


    /**
     * 判断是否是有效的Email.
     * 
     * @param value
     *            字符串值
     * @return true or false
     */
    public static boolean isEmail(String value) {
        return validateFormat(value, IS_EMAIL);
    }

    /**
     * 判断是否是有效的手机号码.
     * 
     * @param value
     *            字符串值
     * @return true or false
     */
    public static boolean isMobile(String value){
        return validateFormat(value, IS_MOBILE);
    }
    
    /**
     * 判断是否是有效的身份证.
     * 
     * @param value
     *            字符串值
     * @return true or false
     */
    public static boolean isID(String value){
    	return validateFormat(value, IS_ID);
    }
}
